package cn.tuling.controller;

import cn.tuling.entity.DO.Order;
import cn.tuling.entity.DO.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


@RestController
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/order/{orderId}")
    public Order getProduct(@PathVariable Integer orderId) {

        Product product = restTemplate.getForObject("http://product-service/product/1", Product.class);
        if (product == null) {
            return null;
        }

        String pay = restTemplate.getForObject("http://ribbon-pay/pay", String.class);


        return new Order(orderId, "随便订单", product, pay);
    }

    @GetMapping("/order/pay")
    public String getPay() {

        String pay = restTemplate.getForObject("http://ribbon-pay/pay", String.class);
        return pay;
    }
}
